package gold.digger;

import gold.vo.TreeNode;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC530 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int minDiff = Integer.MAX_VALUE;
        public int preVal = Integer.MAX_VALUE;

        public int getMinimumDifference(TreeNode root) {
            minTravel(root);
            return minDiff;
        }

        public void minTravel(TreeNode root) {
            if (null == root) return;
            minTravel(root.left);
            minDiff = Math.min(minDiff, Math.abs(root.val - preVal));
            preVal = root.val;
            minTravel(root.right);
        }

    }

    public void run() {
        Solution solution = new Solution();
        TreeNode root = TreeNode.createTree("1,null,3,2");
        System.out.println(solution.getMinimumDifference(root));
    }

    public static void main(String[] args) throws Exception {
        LC530 an = new LC530();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
